import { PayloadUser } from '@libs/common/decorator';
import { IndexInterceptor } from '@libs/common/interceptors';
import { Body, Controller, Post, UseInterceptors } from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';

import {
  CountPointsDto,
  CreatePointsDto,
  IndexPointsDto,
  ShowPointsDto,
} from './dto/points.dto';
import { PointsService } from './points.service';

@ApiTags('积分')
@Controller('market/points')
export class PointsController {
  constructor(private readonly pointsService: PointsService) {}

  @Post('index')
  @UseInterceptors(new IndexInterceptor())
  index(@Body() dto: IndexPointsDto) {
    return this.pointsService.index(dto);
  }

  @Post('show')
  show(@Body() dto: ShowPointsDto) {
    return this.pointsService.show(dto);
  }

  @Post('create')
  create(@Body() dto: CreatePointsDto, @PayloadUser() user: SC.User.SysInfo) {
    return this.pointsService.create(dto, user);
  }

  @Post('count')
  count(@Body() dto: CountPointsDto) {
    return this.pointsService.count(dto);
  }

  @Post('user')
  user(@PayloadUser() payload: SC.User.SysInfo) {
    return this.pointsService.findUserPoints(payload?.id);
  }
}
